<?php

class FluentForm {

    public $conf;

    public function action($value) {
        $this->conf['action'] = $value;
        return $this;
    }

    public function enctype($value) {
        $this->conf['enctype'] = $value;
        return $this;
    }

    public function hidden($name, $value) {
        $this->conf['hidden'][$name] = $value;
        return $this;
    }

    public function fieldset($id) {
        return new FieldSet($this->conf, $id);
    }

}

class FieldSet extends FluentForm {

    private $id;

    public function __construct(&$conf, $id) {
        $this->id = $id;
        $this->conf = &$conf;
    }

    public function textbox($id, $value, $password = FALSE) {
        return new Input($this->conf, $this->id, $id, $value, $password);
    }

    public function void() {
        $this->conf[$this->id][] = NULL;
        return $this;
    }

}

class Input extends FieldSet {

    private $fieldset;
    private $id;

    public function __construct(&$conf, $fieldset, $id, $value, $password) {
        parent::__construct($this->conf, $fieldset);
        $this->fieldset = $fieldset;
        $this->id = $id;
        $this->conf = &$conf;
        if ($password) {
            $this->conf[$this->fieldset][$this->id]['type'] = 'password';
        }
        $this->conf[$this->fieldset][$this->id]['data'] = $value;
    }

    public function label($label) {
        $this->conf[$this->fieldset][$this->id]['label'] = $label;
        return $this;
    }

    public function attributes($name, $value) {
        $this->conf[$this->fieldset][$this->id]['attributes'][$name] = $value;
        return $this;
    }

}
